//
//  ZSY_HomeListCollectionViewcell.m
//  zsy_BreadTrip
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZSY_HomeListCollectionViewcell.h"

@interface ZSY_HomeListCollectionViewcell ()

@property (nonatomic, retain) ZSY_BaseLabel *index_titleLabel;  // 标题
@property (nonatomic, retain) ZSY_BaseImageView *index_coverImageView;  // 背景图片
@property (nonatomic, retain) ZSY_BaseLabel *userNameLabel; // 名字
@property (nonatomic, retain) ZSY_BaseImageView *avatar_mImageView;  // 头像

@end

@implementation ZSY_HomeListCollectionViewcell

- (void)dealloc {
    [_homeModel release];
    [_allArray release];
    [_index_titleLabel release];
    [_index_coverImageView release];
    [_userNameLabel release];
    [_avatar_mImageView release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)setHomeModel:(ZSY_HomeModel *)homeModel {
    if (_homeModel != homeModel) {
        [_homeModel release];
        _homeModel = [homeModel retain];
    }
    self.index_titleLabel.text = homeModel.index_title;
    self.index_titleLabel.numberOfLines = 0;
    self.index_titleLabel.font = [UIFont systemFontOfSize:12];
    
    NSURL *cover_Url = [NSURL URLWithString:homeModel.index_cover];
    [self.index_coverImageView sd_setImageWithURL:cover_Url placeholderImage:nil];
    
    NSLog(@"string = %@", homeModel.userModel.avatar_m);
    NSURL *head_Url = [NSURL URLWithString:homeModel.userModel.avatar_m];
    [self.avatar_mImageView sd_setImageWithURL:head_Url placeholderImage:nil];
    
    self.userNameLabel.text = homeModel.userModel.name;
    self.userNameLabel.font = [UIFont systemFontOfSize:11];
    self.userNameLabel.textColor = [UIColor lightGrayColor];
}


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
    
    self.contentView.layer.borderWidth = 1;
    self.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
    
    
    ZSY_BaseView *view = [[ZSY_BaseView alloc] initWithFrame:CGRectMake(0, 0, (WIDTH - 30) / 2, 200)];
//    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 3;
    view.layer.masksToBounds = YES;
    [self.contentView addSubview:view];
    
    self.index_coverImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(0, 0, (WIDTH - 30) / 2, 120)];
//    self.index_coverImageView.backgroundColor = [UIColor cyanColor];
    [view addSubview:_index_coverImageView];
    
    self.index_titleLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(10, self.index_coverImageView.frame.size.height + 5, (WIDTH - 50) / 2 - 10, 40)];
//    self.index_titleLabel.backgroundColor = [UIColor lightGrayColor];
    [view addSubview:_index_titleLabel];
    
    self.avatar_mImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(10, self.index_titleLabel.frame.size.height + self.index_coverImageView.frame.size.height + 10, 20, 20)];
    self.avatar_mImageView.layer.cornerRadius = 10;
    self.avatar_mImageView.layer.masksToBounds = YES;
    self.avatar_mImageView.backgroundColor = [UIColor blackColor];
    [view addSubview:_avatar_mImageView];
    
    self.userNameLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(self.avatar_mImageView.frame.size.width + 20, self.index_titleLabel.frame.size.height + self.index_coverImageView.frame.size.height + 15, 100, 10)];
//    self.userNameLabel.backgroundColor = [UIColor greenColor];
    [view addSubview:_userNameLabel];
    
    [view release];
    [_index_titleLabel release];
    [_index_coverImageView release];
    [_userNameLabel release];
    [_avatar_mImageView release];
    
}

@end
